
function getSub(id){
	var result = [];

	var subUrl = API_URL + "menu_info?query=delflag:0,fatherId:"+id+"&sortby=menuDisplayOrder&order=asc" 
 $.ajax({
  url : subUrl,
  type : 'get',
  async:false,
  data : {
  },
  cache : false,
  success : function(data) {

    result =  data;
  }
});
 return result;

}

app.controller('menuTopCtrl', function($scope, $http) {

  var platform  ;
  $scope.$on('platform', function(event,data) {

    console.log('platform have changed...')

    platform = data;
    var platformurl = API_URL + "menu_info?query=delflag:0,fatherId:0,MenuLayer:"+platform+"&sortby=menuDisplayOrder&order=asc"    
    $http.get(platformurl).success(function (response) {
      if(null != response){
        for(var i= 0; i<response.length; i++){
          response[i].subMenu = getSub(response[i].Id);
        }
      }
      $scope.topMenus = response;
    });
  });






  var url = API_URL + "menu_info?query=delflag:0,fatherId:0&sortby=menuDisplayOrder&order=asc"    
  $http.get(url).success(function (response) {
   if(null != response){
    for(var i= 0; i<response.length; i++){
     response[i].subMenu = getSub(response[i].Id);
   }
 }

 $scope.topMenus = response;
});

});















